package cn.xd.security.adivce;

import cn.xd.common.enums.common.ResultCodeEnum;
import cn.xd.common.response.ResponseResult;
import cn.xd.security.constants.SecurityConstant;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @author : mirzaLin
 * @data : 2023/11/19
 * @description : 异常处理器
 **/
@RestControllerAdvice
@Slf4j
public class SecurityExceptionAdvice {
    @ExceptionHandler(BadCredentialsException.class)
    public ResponseResult<?> BadCredentialsExceptionHandler(HttpServletRequest req, BadCredentialsException e) {
        return ResponseResult.failed(SecurityConstant.USERNAME_PASSWORD_ERROR, ResultCodeEnum.BIZ_ERROR);
    }
}
